﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SourceCode.SmartObjects.Client;
using SourceCode.Hosting.Client.BaseAPI;

namespace Eform.Data
{
    public sealed class SOServer
    {
        //private static string SERVERNAME = Params.SERVER;
        private static SmartObjectClientServer server = null;
        private static SCConnectionStringBuilder cb = null;
        private static SOServer _instance = null;

        public static SOServer Instance()
        {
            if (_instance == null)
            {
                _instance = new SOServer();
            }
            return _instance;
        }

        private SOServer()
        {
            cb = new SCConnectionStringBuilder();
            cb.Host = Params.SERVER;
            cb.Port = 5555;
            cb.Integrated = true;
            cb.IsPrimaryLogin = true;
            

            server = new SmartObjectClientServer();
            server.CreateConnection();
        }

        public void Open()
        {
            server.Connection.Open(cb.ToString());
        }

        public void Close()
        {
            if (null != server.Connection)
            {
                server.Connection.Close();
            }
        }

        public SmartObject GetSmartObject(string SmartObjectName)
        {
            return server.GetSmartObject(SmartObjectName);
        }

        public SmartObject ExecuteScalar(SmartObject so)
        {
            return server.ExecuteScalar(so);
        }

        public SmartObjectList ExecuteList(SmartObject so)
        {
            return server.ExecuteList(so);
        }
    }
}
